package com.twenty.seven.apollo.demo.netty;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

import java.util.Arrays;

public class DirectByteBufDemo {

    public static void main(String[] args) {
        ByteBuf buf = Unpooled.directBuffer(10);
        System.out.println("原始ByteBuf内容：：：：：："+buf.toString());

        // 2.写入一段内容
        byte[] bytes = {1, 2, 3, 4, 5};
        buf.writeBytes(bytes);
        System.out.println("写入的bytes为====================>" + Arrays.toString(bytes));
        System.out.println("写入一段内容后ByteBuf为===========>" + buf.toString());

        byte b1 = buf.readByte();
        byte b2 = buf.readByte();
        System.out.println("读取的bytes为：：：：："+Arrays.toString(new byte[]{b1,b2}));
        System.out.println(buf.toString());
        byte b3 = buf.readByte();
        System.out.println("读取的bytes为：：：：："+Arrays.toString(new byte[]{b3}));
        System.out.println(buf.toString());
        buf.discardReadBytes();
        System.out.println(buf.toString());
        byte b4 = buf.readByte();
        System.out.println("读取的bytes为：：：：："+Arrays.toString(new byte[]{b4}));
        System.out.println(buf.toString());

        buf.clear();
        System.out.println(buf.toString());

        buf.writeBytes(new byte[]{1,2,3});
        System.out.println(buf.toString());

        buf.setZero(0,buf.capacity());
        System.out.println(buf.toString());

        buf.writeBytes(new byte[]{1,2,3,4,5,6,7,8,9,0});
        System.out.println(buf.toString());

    }
}
